/**
 * 
 */
package org.statewalker.validator.impl;

public class IdGenerator {

    private static int fInstanceCounter;

    private int fCounter;

    private final int fInstanceId;

    public IdGenerator() {
        fInstanceId = fInstanceCounter++;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this)
            return true;
        if (!(obj instanceof IdGenerator))
            return false;
        IdGenerator o = (IdGenerator) obj;
        return o.fInstanceId == fInstanceId;
    }

    @Override
    public int hashCode() {
        return fInstanceId;
    }

    public int newId() {
        return fCounter++;
    }

    @Override
    public String toString() {
        return "IdGenerator[" + fInstanceId + "]";
    }
}